package com.ctrip.demo.leetcode;

import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class MergeSort {

    public static void main(String[] args) {

        Map<String, int[]> map = new HashMap<>();
        map.put("1", new int[]{1});

        int[] var = map.get("1");

        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] nums = new int[n];
        for (int i = 0; i < n; ++i) {
            nums[i] = sc.nextInt();
        }
        mergeSort(nums, 0, n - 1);
        for (int i = 0; i < n; ++i) {
            System.out.printf("%d ", nums[i]);
        }

    }

    private static int[] tmp = new int[1000];

    public static void mergeSort(int[] nums, int left, int right) {
        if (left >= right) {
            return;
        }
        int mid = (left + right) >>> 1;
        mergeSort(nums, left, mid);
        mergeSort(nums, mid + 1, right);

        int i = left, j = mid + 1, k = 0;
        while(i <= mid && j <= right) {
            if (nums[i] <= nums[j]) {
                tmp[k++] = nums[i ++];
             } else {
                tmp[k ++] = nums[j ++];
            }
        }
        while (i <= mid) {
            tmp[k++] = nums[i++];
        }
        while (j <= right) {
            tmp[k++] = nums[j++];
        }
        for (i = left, j = 0; i <= right; ++i,++j) {
            nums[i] = tmp[j];
        }
    }
}
